{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Detecting outliers with the median absolute deviation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import seaborn as sns\n",
    "from sklearn.datasets import load_breast_cancer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>mean radius</th>\n",
       "      <th>mean texture</th>\n",
       "      <th>mean perimeter</th>\n",
       "      <th>mean area</th>\n",
       "      <th>mean smoothness</th>\n",
       "      <th>mean compactness</th>\n",
       "      <th>mean concavity</th>\n",
       "      <th>mean concave points</th>\n",
       "      <th>mean symmetry</th>\n",
       "      <th>mean fractal dimension</th>\n",
       "      <th>...</th>\n",
       "      <th>worst radius</th>\n",
       "      <th>worst texture</th>\n",
       "      <th>worst perimeter</th>\n",
       "      <th>worst area</th>\n",
       "      <th>worst smoothness</th>\n",
       "      <th>worst compactness</th>\n",
       "      <th>worst concavity</th>\n",
       "      <th>worst concave points</th>\n",
       "      <th>worst symmetry</th>\n",
       "      <th>worst fractal dimension</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>17.99</td>\n",
       "      <td>10.38</td>\n",
       "      <td>122.80</td>\n",
       "      <td>1001.0</td>\n",
       "      <td>0.11840</td>\n",
       "      <td>0.27760</td>\n",
       "      <td>0.3001</td>\n",
       "      <td>0.14710</td>\n",
       "      <td>0.2419</td>\n",
       "      <td>0.07871</td>\n",
       "      <td>...</td>\n",
       "      <td>25.38</td>\n",
       "      <td>17.33</td>\n",
       "      <td>184.60</td>\n",
       "      <td>2019.0</td>\n",
       "      <td>0.1622</td>\n",
       "      <td>0.6656</td>\n",
       "      <td>0.7119</td>\n",
       "      <td>0.2654</td>\n",
       "      <td>0.4601</td>\n",
       "      <td>0.11890</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>20.57</td>\n",
       "      <td>17.77</td>\n",
       "      <td>132.90</td>\n",
       "      <td>1326.0</td>\n",
       "      <td>0.08474</td>\n",
       "      <td>0.07864</td>\n",
       "      <td>0.0869</td>\n",
       "      <td>0.07017</td>\n",
       "      <td>0.1812</td>\n",
       "      <td>0.05667</td>\n",
       "      <td>...</td>\n",
       "      <td>24.99</td>\n",
       "      <td>23.41</td>\n",
       "      <td>158.80</td>\n",
       "      <td>1956.0</td>\n",
       "      <td>0.1238</td>\n",
       "      <td>0.1866</td>\n",
       "      <td>0.2416</td>\n",
       "      <td>0.1860</td>\n",
       "      <td>0.2750</td>\n",
       "      <td>0.08902</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>19.69</td>\n",
       "      <td>21.25</td>\n",
       "      <td>130.00</td>\n",
       "      <td>1203.0</td>\n",
       "      <td>0.10960</td>\n",
       "      <td>0.15990</td>\n",
       "      <td>0.1974</td>\n",
       "      <td>0.12790</td>\n",
       "      <td>0.2069</td>\n",
       "      <td>0.05999</td>\n",
       "      <td>...</td>\n",
       "      <td>23.57</td>\n",
       "      <td>25.53</td>\n",
       "      <td>152.50</td>\n",
       "      <td>1709.0</td>\n",
       "      <td>0.1444</td>\n",
       "      <td>0.4245</td>\n",
       "      <td>0.4504</td>\n",
       "      <td>0.2430</td>\n",
       "      <td>0.3613</td>\n",
       "      <td>0.08758</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>11.42</td>\n",
       "      <td>20.38</td>\n",
       "      <td>77.58</td>\n",
       "      <td>386.1</td>\n",
       "      <td>0.14250</td>\n",
       "      <td>0.28390</td>\n",
       "      <td>0.2414</td>\n",
       "      <td>0.10520</td>\n",
       "      <td>0.2597</td>\n",
       "      <td>0.09744</td>\n",
       "      <td>...</td>\n",
       "      <td>14.91</td>\n",
       "      <td>26.50</td>\n",
       "      <td>98.87</td>\n",
       "      <td>567.7</td>\n",
       "      <td>0.2098</td>\n",
       "      <td>0.8663</td>\n",
       "      <td>0.6869</td>\n",
       "      <td>0.2575</td>\n",
       "      <td>0.6638</td>\n",
       "      <td>0.17300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>20.29</td>\n",
       "      <td>14.34</td>\n",
       "      <td>135.10</td>\n",
       "      <td>1297.0</td>\n",
       "      <td>0.10030</td>\n",
       "      <td>0.13280</td>\n",
       "      <td>0.1980</td>\n",
       "      <td>0.10430</td>\n",
       "      <td>0.1809</td>\n",
       "      <td>0.05883</td>\n",
       "      <td>...</td>\n",
       "      <td>22.54</td>\n",
       "      <td>16.67</td>\n",
       "      <td>152.20</td>\n",
       "      <td>1575.0</td>\n",
       "      <td>0.1374</td>\n",
       "      <td>0.2050</td>\n",
       "      <td>0.4000</td>\n",
       "      <td>0.1625</td>\n",
       "      <td>0.2364</td>\n",
       "      <td>0.07678</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 30 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   mean radius  mean texture  mean perimeter  mean area  mean smoothness  \\\n",
       "0        17.99         10.38          122.80     1001.0          0.11840   \n",
       "1        20.57         17.77          132.90     1326.0          0.08474   \n",
       "2        19.69         21.25          130.00     1203.0          0.10960   \n",
       "3        11.42         20.38           77.58      386.1          0.14250   \n",
       "4        20.29         14.34          135.10     1297.0          0.10030   \n",
       "\n",
       "   mean compactness  mean concavity  mean concave points  mean symmetry  \\\n",
       "0           0.27760          0.3001              0.14710         0.2419   \n",
       "1           0.07864          0.0869              0.07017         0.1812   \n",
       "2           0.15990          0.1974              0.12790         0.2069   \n",
       "3           0.28390          0.2414              0.10520         0.2597   \n",
       "4           0.13280          0.1980              0.10430         0.1809   \n",
       "\n",
       "   mean fractal dimension  ...  worst radius  worst texture  worst perimeter  \\\n",
       "0                 0.07871  ...         25.38          17.33           184.60   \n",
       "1                 0.05667  ...         24.99          23.41           158.80   \n",
       "2                 0.05999  ...         23.57          25.53           152.50   \n",
       "3                 0.09744  ...         14.91          26.50            98.87   \n",
       "4                 0.05883  ...         22.54          16.67           152.20   \n",
       "\n",
       "   worst area  worst smoothness  worst compactness  worst concavity  \\\n",
       "0      2019.0            0.1622             0.6656           0.7119   \n",
       "1      1956.0            0.1238             0.1866           0.2416   \n",
       "2      1709.0            0.1444             0.4245           0.4504   \n",
       "3       567.7            0.2098             0.8663           0.6869   \n",
       "4      1575.0            0.1374             0.2050           0.4000   \n",
       "\n",
       "   worst concave points  worst symmetry  worst fractal dimension  \n",
       "0                0.2654          0.4601                  0.11890  \n",
       "1                0.1860          0.2750                  0.08902  \n",
       "2                0.2430          0.3613                  0.08758  \n",
       "3                0.2575          0.6638                  0.17300  \n",
       "4                0.1625          0.2364                  0.07678  \n",
       "\n",
       "[5 rows x 30 columns]"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X, y = load_breast_cancer(return_X_y=True, as_frame=True)\n",
    "\n",
    "# display top 5 rows\n",
    "X.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "def plot_boxplot_and_hist(data, variable):\n",
    "    # creating a figure composed of two matplotlib.Axes objects (ax_box and ax_hist)\n",
    "    f, (ax_box, ax_hist) = plt.subplots(\n",
    "        2, sharex=True, gridspec_kw={\"height_ratios\": (0.50, 0.85)}\n",
    "    )\n",
    "\n",
    "    # assigning a graph to each ax\n",
    "    sns.boxplot(x=data[variable], ax=ax_box)\n",
    "    sns.histplot(data=data, x=variable, ax=ax_hist)\n",
    "\n",
    "    # Remove x axis name for the boxplot\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAEGCAYAAABiq/5QAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/H5lhTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAV2klEQVR4nO3de5SddX3v8fc3GWLkIokkZUHIdHB5OXWRtvEMnIqXk5LqsS2KF5a61IgXTrqOS621JWA9a5XTc8NIT6XtOWoKlJByChJBqFqQpmAvCmZCkOEiSlGSISiBSlU8LYn5nj+eJ2Q7mWT2ntnP3jPze7/W2mv2fq7f38zen/3Mbz/Pb0dmIkkqx7x+FyBJ6i2DX5IKY/BLUmEMfkkqjMEvSYUZ6HcB7ViyZEkODQ31uwxJmlW2bdv2eGYuHT99VgT/0NAQIyMj/S5DkmaViHh4oul29UhSYQx+SSqMwS9JhTH4JakwBr8kFcbgl6TCzIrTOTW7vOFNZ/P9Jx7vdxlds/i4JVz/2c39LkPqGoNfXff9Jx7nh6e+p/H9HLP18p7sh62XN78PqYfs6pGkwhj8klQYg1+SCmPwS1JhDH5JKozBL0mFMfglqTAGvyQVxuCXpMIY/JJUGINfkgpj8EtSYQz+Llq1alW/S5BmBF8LM5vBL0mFMfglqTAGvyQVxuCXpMIY/JJUGINfkgpj8EtSYQx+SSqMwS9JhTH4JakwBr8kFWag3wU0ZcuWLWzatIkdO3YwODjImjVrWL16db/LksTkr8/DzT/UvLn0mm+6LXMy+Lds2cKll17KunXrWLFiBaOjo6xfvx5g1j4RpLlistfn4eYDE8675557uP322+fEa74X+TUnu3o2bdr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vBD4Jh265vAzcB7IuLouv5lEfEzEXEi8OPM/HPg48BL6mWOzcwvAr9F9caownnEr9nmvwKfAO6uA/vbwJnA/wE+GxHvpOqOeaqDbc4H/jwijqU6mv6jzHxygs+AD5KZ/xIR7waujWpI7q1U3138rxNNr1fbANwUEbsy85c7qHP/Pr8UET8HfLWu8UdUo3E+H/h4ROyjGpnzP1G9wdwQEQvrtn240/1p7nF0TkkqjF09klQYg1+SCmPwS1JhDH5JKozBL0mFMfglqTAGvyQV5v8DBerEmuyMrSAAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_boxplot_and_hist(X, \"mean smoothness\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "def find_limits(df, variable, fold):\n",
    "    median = df[variable].median()\n",
    "    center = df[variable] - median\n",
    "    MAD = center.abs().median() * 1.4826\n",
    "    lower_limit = median - fold * MAD\n",
    "    upper_limit = median + fold * MAD\n",
    "    return lower_limit, upper_limit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(0.05361590000000002, 0.13812409999999997)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# we find the limits\n",
    "\n",
    "lower_limit, upper_limit = find_limits(X, \"mean smoothness\", 3)\n",
    "lower_limit, upper_limit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "# let's flag the outliers in the data set\n",
    "\n",
    "outliers = np.where(\n",
    "    (X[\"mean smoothness\"] > upper_limit) | \n",
    "    (X[\"mean smoothness\"] < lower_limit),\n",
    "    True,\n",
    "    False,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# how many outliers did we find?\n",
    "\n",
    "outliers.sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "def plot_boxplot_and_hist(data, variable):\n",
    "    f, (ax_box, ax_hist) = plt.subplots(\n",
    "        2, sharex=True, gridspec_kw={\"height_ratios\": (0.50, 0.85)}\n",
    "    )\n",
    "\n",
    "    sns.boxplot(x=data[variable], ax=ax_box)\n",
    "    sns.histplot(data=data, x=variable, ax=ax_hist)\n",
    "    \n",
    "    plt.vlines(x=lower_limit, ymin=0, ymax=80, color='r')\n",
    "    plt.vlines(x=upper_limit, ymin=0, ymax=80, color='r')\n",
    "\n",
    "    plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAEGCAYAAABiq/5QAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/H5lhTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAWBElEQVR4nO3dfbRddX3n8feXXELkQRJJyoKQ24vLh6mLtI1zYSpaJ5Lq0CkWVEZc1YgPTLpq1VodA9auVdvpdDDSqXT6oCkwhJQpaASh6oBMBKetgrkhSHgQpQhJACVQ8QFXJSHf+WPvkOPNTe459559zj33936tddY9Zz+c/f3lnP05O7+z9+9EZiJJKsch/S5AktRbBr8kFcbgl6TCGPySVBiDX5IKM9TvAtqxcOHCHBkZ6XcZkjRQNm/e/HhmLho/fSCCf2RkhLGxsX6XIUkDJSIemmi6XT2SVBiDX5IKY/BLUmEMfkkqjMEvSYUx+CWpMANxOqcGy+vecDbfe+LxfpfRNQuOWci1n9nQ7zKkrjH41XXfe+Jxf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gxTxgmCqc/yYitlKF5Utanvdrmbmjft47Wp6r1Z3AlRHxFqoPoL3+T2buqmuYA9xQT99b04vrur9ZT19HFcIHmj6Rp6nCG6oPvNb6PpuZezLzHqrx5/f+G7wG2ALcDvwbqg+7rcCrI+KjEfHLmfl9qg+9fwUujYjXU314qXBD/S5AavGTlvt7Wh7vYd97NYA3ZOZ9rStGxEeA71IdmR9CFXYTPe8zTPy+/zWqYH4t8OGIWNq6bmbuiYhd9QfR+Jqmq/V5x9fXWnu0/P3vmfnJ8U8UES+lGifmjyNiY2b+Ud1NtoJq8L13Uw+6p3J5xK9BcyPwnr399BGxrJ5+NPBofVS/kurovC1R/bDHksy8GTi/fq4j21z9PmAkIl5QP14JfPkg0wF+CBzVbn0TuBF4R0QcWde/OCJ+JiKOB36cmX8LfAx4ab3M0Zn5BeB3qT4YVTiP+DVo/ivwceDOOrC/DZwB/BXwmYh4K1V3zFMdPOcc4G8j4miqo+k/z8wnJ/gOeD+Z+a8R8Xbg01ENyb2J6reLfzLR9Hq1tcANEfFIZr6qgzr3bvOLEfFzwFfrGn9ENRrnC4CPRcQeqpE5f4vqA+a6iJhXt+39nW5Ps4+jc0pSYezqkaTCGPySVBiDX5IKY/BLUmEMfkkqjMEvSYUx+CWpMP8fvZnSUcG+B94AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_boxplot_and_hist(X, \"mean smoothness\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(6.151025999999991, 44.668974000000006)"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# we find the limits in another variable\n",
    "\n",
    "lower_limit, upper_limit = find_limits(X, \"worst texture\", 3)\n",
    "lower_limit, upper_limit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "# let's flag the outliers in the data set\n",
    "\n",
    "outliers = np.where(\n",
    "    (X[\"worst texture\"] > upper_limit) |\n",
    "    (X[\"worst texture\"] < lower_limit),\n",
    "    True,\n",
    "    False,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# how many outliers did we find?\n",
    "\n",
    "outliers.sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX4AAAEGCAYAAABiq/5QAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjguMywgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy/H5lhTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAT+0lEQVR4nO3df7DddX3n8eeLROovLJBcGQxJQwvT1m1Wsxupgusi6e4wW0ewpWpxs7gLi7urVYo1pe4wzi7TWUxtlel2ihlgYTNQQZRCaccuG8DStYMkRI2ArqxKCCIEhfpjprXR9/5xvpHLzb3Juefeb869+TwfM2fu93y/5/v9vvnoeeVzPud7Pt9UFZKkdhwx7gIkSYeWwS9JjTH4JakxBr8kNcbgl6TGLB13AcNYvnx5rV69etxlSNKisn379qeqamLq+kUR/KtXr2bbtm3jLkOSFpUkj0y33qEeSWqMwS9JjTH4JakxBr8kNcbgl6TGGPyS1JhFcTmnDm9v+tVzePpbT427jEPmmGXLueUTN4+7DDXM4NfYPf2tp/juq/7dIT/vUfddM5bzct81h/6c0iQO9UhSYwx+SWqMwS9JjTH4JakxBr8kNcbgl6TGGPyS1BiDX5IaY/BLUmMMfklqjMEvSY0x+CWpMQb/AnD66aePuwRpUfM9NDsGvyQ1xuCXpMYY/JLU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l6TGGPyS1BiDX5pBkrO7CeZmtW3IY1+U5IWjVyeNzuBX85IsmWHT2cBM4X6gbcO4CJhV8E/6Jas0Jwa/Fq0k70vy7m75w0nu7JbPSHJ9t/zr3ZzmX0zywUn7fi/J7yf5PPCaJJd39xD4QpIPJTkVeCPwe9186D8zad/9tnWPT3UTat2T5OeSLE1y3745aJL8tyS/29X8MuCuJHftq2fS8c9Jcm23fG2SK5PcC2ya7jy9NbAOX1Xlw8eifDCY7//j3fI9wGcZTHf8AeAdDMJ1FzDB4NePdwJnd68vBr96hMFskF/m2R80Ht39vRY4Z4ZzP2cbg7nRT+6Wf5HB1AMA/4jB1Ay/xOAXqEd2678OLJ+0//cmLZ8DXDvpPLcDSw50Hh8+ZvPwo6MWs+3AP03yEgY3OrkfWAf8M+DdwKuAu6tqD0D3KeB1DKbW+CGDieQA/hb4O+Dq7g5Qt8+miG4m0lOBj0+ahfQnAKrqgSRbumO+pqp+MMJ/58er6ocHOo80Gwa/Fq2q+ockXwPeDnwG+ALweuAkBr3skw+w+9/VYJpkqmpvklOA9Qx62+9iMEvksI5gMH/8K2fYvgZ4BnjpAY4xee6U50/Z9v0hzyMNxTF+LXb3AL8F/FW3/B+AHVVVDIZ+/nmS5d0XuL8OfHrqAbqe9E9W1V8Avwm8otv0XeCoGc77421V9R3ga0l+rTtekryiW/4VBhONvQ74w30zdE5z7CeS/HySI4A3TXfCA51Hmg2DX4vdPcDxwN9U1RMMhmzugcFtIBnck/Qu4PPA9qqabhrbo4Dbk3wB+Gvg4m79x4D3ZXAT8J+Zss/UbW8Dzu++LH4AOCvJcuBy4IKq+r/Af2cw1zzAZuBT+77c7eq8ncEnl8eZ2X7nOXDzSPtzdk5Jaow9fklqjMEvSY0x+CWpMQa/JDXG4Jekxhj8ktQYg1+SGvP/AVNG9UuHPb2DAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plot_boxplot_and_hist(X, \"worst texture\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "fsml",
   "language": "python",
   "name": "fsml"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
